package com.softeem.god.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.softeem.god.entity.Blacklist;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author Administrator
* @description 针对表【blacklist(用户黑名单表)】的数据库操作Mapper
* @createDate 2025-11-01 14:00:00
*/
@Mapper
public interface BlacklistMapper extends BaseMapper<Blacklist> {
    
    /**
     * 关联用户表分页查询黑名单列表
     * @param page 分页对象
     * @param username 用户名（模糊查询）
     * @return 分页结果
     */
    @Select("SELECT b.*, u.username FROM blacklist b LEFT JOIN user u ON b.user_id = u.id " +
           "WHERE ${ew.sqlSegment != null and ew.sqlSegment != '' ? ew.sqlSegment : '1=1'}")
    IPage<Blacklist> selectBlacklistWithUser(Page<Blacklist> page, @Param("ew") com.baomidou.mybatisplus.core.conditions.Wrapper<Blacklist> wrapper);
    
    /**
     * 根据用户ID查询黑名单记录
     * @param userId 用户ID
     * @return 黑名单记录列表
     */
    @Select("SELECT * FROM blacklist WHERE user_id = #{userId} ORDER BY create_time DESC")
    List<Blacklist> selectByUserId(Integer userId);
}